package com.dd.controller;


import com.dd.common.aop.annation.Login;
import com.dd.common.response.Result;
import com.dd.common.utils.HttpUtils;
import com.dd.pojo.entry.User;
import com.dd.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户接口")
public class UserController {

    private final UserService userService;

   @PostMapping("/register")
   @ApiOperation("用户注册")
    public Result<?> userRegister(@Valid @RequestBody User user){
        userService.userRegister(user);
        return Result.success();
   }

   @PostMapping("/info")
   @ApiOperation("查询用户信息")
   @Login
   public Result<?> findUserInfo(HttpServletRequest request){
       String userId= HttpUtils.anasyUserId(request);
       return Result.success(userId);
   }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Result<String> userLogin(@RequestBody User user){
        String token= userService.userLogin(user);
        return Result.success(token);
    }

    @PostMapping("/userLogOut")
    @ApiOperation("用户注销登录")
    public Result<String> userLogOut(@RequestBody User user){

       return Result.success("注销登录");
    }

}
